<?php
/**
 * 根据trade执行BUY操作。
 * TransHistory
 */
require 'config.php';
require 'Lib_btc.php';

$user = getBtcAccount(BTC_DEFAULT_USER);
$rules = getAllRules();
if( !empty($rules) )
	foreach( $rules AS $rule )
{
	$pair = $rule['pair'];
	$buy_num = getBuyNum( $rule, $user ); // 要买多少
	$toBuys = getRateAmountToBuys( $rule, $buy_num ); // 要买哪些
	$i=0;
	if( !empty($toBuys) )
		foreach( $toBuys AS $buy )
	{
		$i++;
		$result = btce_query("Trade",
						array("pair" => $rule['pair'],
							 	"type" => "buy",
								"amount" => $buy['amount'],
								"rate" => $buy['price']
							)
				);
	}
	logBtcApiResult('BuyOrder:'.$rule['pair'],'获取交易数量：'.$i.'个。');

}
echo "<script>
<!--
setTimeout(function(){location.replace(location.href);},300000);
//-->
</script>";
?>
